package Demo2;

public class Demo10 {
    public static void main(String[] args) throws InterruptedException {
     Thread t=new Thread(()->{
        while(!Thread.currentThread().isInterrupted()){
            System.out.println("hello Threa");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                break;
            }
        }
         System.out.println("t线程结束");
     });
t.start();

Thread.sleep(5000);
        System.out.println("main线程尝试终止t线程");
     t.interrupt();
    }
}
